<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">
        window.onload = function () {
            //获取ID下面的className
            function getClassNames(id, classname) {//封装语句
                //支持getElementsByClassName的情况下
                if (document.getElementsByClassName) {
                    if (id) {//有ID的情况下
                        var arrId = document.getElementById(id);
                        return arrId.getElementsByClassName(classname);
                    } else {
                        return document.getElementsByClassName(classname);
                    }
                } else {//不支持getElementsByClassName的情况下
                    if (id) {
                        var arrId = document.getElementById(id);
                        var dom = arrId.getElementsByTagName("*");
                        var arr = [];
                        for (var i = 0; i < dom.length; i++) {
                            var txtArr = dom[i].className.split(" ");
                            for (var j = 0; j < txtArr.length; j++) {
                                if (txtArr[j] == classname) {
                                    arr.push(dom[i]);
                                }
                            }
                        }
                        return arr;
                    }
                }
            }


            var lis = getClassNames('box', 'cur')
        }


    </script>
</head>
<body>

<div id="box">
    <ul id="ul">
        <li class="r cur">dsfsfs</li>
        <li class="r cur">fdsafsaf</li>
        <li class="r cur">fdsafdsafs</li>
    </ul>
</div>

</body>
</html>